//===============================================================================
// Microsoft patterns & practices
// Guidance Explorer Offline Client
//===============================================================================
// Copyright  Microsoft Corporation.  All rights reserved.
// THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY
// OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT
// LIMITED TO THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
// FITNESS FOR A PARTICULAR PURPOSE.
//===============================================================================

using System;
using System.IO;
using System.Xml;
using GuidanceExplorer.Model;

namespace GuidanceExplorer.Services
{
    public interface IModelStorageService
    {
        /// <summary>
        /// Load guidance and return the intance.
        /// </summary>
        /// <param name="currentDirectory">The current directory for the process.</param>
        /// <returns>An instance of the Guidance loaded from file.</returns>
        Guidance LoadGuidance(string currentDirectory, ClientFlavour clientFlavour);

        /// <summary>
        /// The previously loaded guidance instance.
        /// </summary>
        Guidance Guidance { get;}

        /// <summary>
        /// Render the library instance to an FileInfo.
        /// </summary>
        /// <param name="library">The library to render.</param>
        /// <param name="fileInfo">The fileInfo to render to.</param>
        void RenderLibraryToFileInfo(Library library, FileInfo fileInfo);

        /// <summary>
        /// Renders a Guidance in the model to the set of files in the Libraries folder.
        /// </summary>
        /// <param name="guidance">The Guidance instance to process.</param>
        /// <param name="currentDirectory">The current directory for this process.</param>
        void SaveGuidance(Guidance guidance, string currentDirectory);

        /// <summary>
        /// Finds an item across all libraries by using it's Id.
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        GuidanceItem FindItemById(string id);

        /// <summary>
        /// Covnverts a FileInfo into a Library
        /// </summary>
        /// <param name="fileInfo">The instance of the file info the convert.</param>
        /// <returns>The new Library instance.</returns>
        Library ConvertFileInfoToLibrary(FileInfo fileInfo);

        /// <summary>
        /// Render an instance of a GuidanceItem to it's format in Xml.
        /// </summary>
        /// <param name="guidanceItem">The instance of the Guidance Item.</param>
        /// <param name="fileInfo">The file where it must be saved.</param>
        /// <param name="htmlContent">The HTML content for the item.</param>
        void RenderGuidanceItemToFileInfo(GuidanceItemFileReference guidanceItem, FileInfo fileInfo, string htmlContent);

        /// <summary>
        /// Render an instance of a GuidanceItem to it's format in Xml.
        /// </summary>
        /// <param name="guidanceItem"></param>
        /// <param name="htmlContent"></param>
        /// <param name="writer"></param>
        void RenderGuidanceItemToXmlWriter(GuidanceItemFileReference guidanceItem, string htmlContent, XmlWriter writer);

        /// <summary>
        /// Render an instance of a GuidanceItem to it's format in Html.
        /// </summary>
        /// <param name="guidanceItem">The instance of the Guidance Item.</param>
        /// <param name="fileInfo">The file where it must be saved.</param>
        /// <param name="htmlContent">The Guidance Item's html content</param>
        void RenderGuidanceItemToHtmlFileInfo(GuidanceItemFileReference guidanceItem, FileInfo fileInfo, Stream htmlContent);

        /// <summary>
        /// Removes the guidance from the local store.
        /// </summary>
        /// <param name="guidanceItem"></param>
        /// <param name="library"></param>
        void DeleteGuidanceItem(GuidanceItem guidanceItem, Library library);

        /// <summary>
        /// Remove the guidance item from the view.
        /// </summary>
        /// <param name="view"></param>
        /// <param name="guidanceItem"></param>
        void DeleteGuidanceItemFromView(GuidanceExplorer.Model.View view, GuidanceItem guidanceItem);

        /// <summary>
        /// Removes the guidance item recursivelly from all the folders.
        /// </summary>
        /// <param name="folderCollection"></param>
        /// <param name="guidanceItem"></param>
        void RemoveGuidanceItemFromAllViews(FolderCollection folderCollection, GuidanceItem guidanceItem);

        /// <summary>
        /// Removes the guidance item recursivelly from all the views within all the folders.
        /// </summary>
        /// <param name="library"></param>
        /// <param name="guidanceItem"></param>
        void RemoveGuidanceItemFromLibrary(Library library, GuidanceItem guidanceItem);

        /// <summary>
        /// Add a GuidanceItem to a view.
        /// </summary>
        /// <param name="view"></param>
        /// <param name="guidanceItem"></param>
        void AddGuidanceItemToView(GuidanceExplorer.Model.View view, GuidanceItem guidanceItem);

		/// <summary>
		/// Add a GuidanceItem to a CheckList.
		/// </summary>
		/// <param name="CheckList"></param>
		/// <param name="guidanceItem"></param>
		void AddGuidanceItemToCheckList(Checklist checkList, GuidanceItem guidanceItem);

        /// <summary>
        /// Add a GuidanceItem to a Library
        /// </summary>
        /// <param name="library"></param>
        /// <param name="guidanceItem"></param>
        void AddGuidanceItemToLibrary(Library library, GuidanceItem guidanceItem);

        /// <summary>
        /// 
        /// </summary>
        /// <param name="itemContainer"></param>
        /// <param name="name"></param>
        /// <param name="guidanceItems"></param>
        /// <param name="fileInfo"></param>
        /// <param name="htmlService"></param>
        void ExportAsLibrary(IGuidanceItemContainer itemContainer, String name, FileInfo fileInfo, IHtmlRenderService htmlService);

        /// <summary>
        /// Updates the metadata in the index using the information in the gifr.
        /// </summary>
        /// <param name="guidanceItem"></param>
        /// <param name="deleted"></param>
        void UpdateIndex(GuidanceItemFileReference guidanceItem, bool deleted);
    }
}
